package org.come.Jpanel;

import java.awt.*;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import org.come.bean.ConfigureBean;
import org.come.model.Configure;
import org.come.model.Eshop;
import org.come.until.CutButtonImage;
import org.come.until.DeviceEshopUntil;

import com.tool.btn.TaoBaoBtn;
import com.tool.tcpimg.UIUtils;
import com.updateNew.MyIsif;
import org.come.until.UserMessUntil;

public class ShopOnlineJpanel extends JPanel {



    /** 7-17-HGC-start */
    // private TaoBaoBtn[] menuLable = new TaoBaoBtn[6];
    /**
     * 珍品treasureMenuBtn<br>
     * 技能skillMenuBtn<br>
     * 神兽mythicalMenuBtn<br>
     * 仙器deviceMenuBtn<br>
     * 配饰baldricMenuBtn<br>
     * 积分integralMenuBtn<br>
     * 技能skillBookMenuBtn<br>
     * 符石questMenuBtn<br>
     * 开孔trepanningMenuBtn<br>
     */
    private TaoBaoBtn treasureMenuBtn, skillMenuBtn, mythicalMenuBtn, deviceMenuBtn, 
    baldricMenuBtn, integralMenuBtn,skillBookMenuBtn,questMenuBtn,trepanningMenuBtn;

    /** 7-17-HGC-end */
    private GoodsMinJpanel[] goodsMinJpanels = new GoodsMinJpanel[9]; //
    private TaoBaoBtn btnhp,// 首页
            btnep,// 末页
            btnsyy,// 上一页
            btnxyy;// 下一页
    private JLabel labpage; // 放置当前页数和总页数
    private int nowPage = 1; // 当前页数
    private int maxPage = 1; // 最大页码
    /** "珍品"-6, "技能"-7, "神兽"-8, "仙器"-9, "配饰"-10, "积分"-11  "技能书"-12  "珍品" -13 ""-14*/
    private int shopType = 6;

    public ShopOnlineJpanel() {
            this.setLayout(null);
            this.setPreferredSize(new Dimension(802, 538));
            this.setOpaque(false);
            this.setBackground(UIUtils.Color_BACK);
            labpage = new JLabel("1/1", SwingConstants.CENTER);
            labpage.setForeground(Color.white);
            labpage.setBounds(425, 435, 65, 20);
            labpage.setFont(UIUtils.TEXT_FONT1);
            this.add(labpage);
            // 首页
            btnhp = new TaoBaoBtn("inkImg/number/b8/shou.png", 1, "", 20, this);
            btnhp.setBounds(338, 435, 53, 20);
            this.add(btnhp);
            // 上一页
            btnsyy = new TaoBaoBtn("inkImg/number/b8/btn1-left.png", 1, "", 21, this);
            btnsyy.setBounds(401, 435, 19, 20);
            this.add(btnsyy);
            // 下一页
            btnxyy = new TaoBaoBtn("inkImg/number/b8/btn1-right.png", 1, "", 22, this);
            btnxyy.setBounds(500, 435, 19, 20);
            this.add(btnxyy);
            // 末页
            btnep = new TaoBaoBtn("inkImg/number/b8/wei.png", 1, "", 23, this);
            btnep.setBounds(520, 435, 53, 20);
            this.add(btnep);
            /** 7-17-HGC-start */
            // String[] menuStr = new String[] { "珍品", "技能", "神兽", "仙器", "配饰", "积分"
            // };
            // // 设置菜单按钮监听
            // for (int i = 0; i < menuStr.length; i++) {
            // menuLable[i] = new TaoBaoBtn("skin/8100226/button/3.png", 1, menuStr[i], i
            // + 10, this);
            // menuLable[i].setBounds(54 + i * 77, 14, 63, 26);
            // this.add(menuLable[i]);
            // }
            // try {
            // menuLable[0].setIcons(CutButtonImage.cuts("skin/8100226/button/4.png"));
            // } catch (Exception e) {
            // e.printStackTrace();
            // }
            getTreasureMenuBtn();
//            getTreasureMenuBtn();
            getSkillMenuBtn();
            getMythicalMenuBtn();
            getDeviceMenuBtn();
            getBaldricMenuBtn();
            getIntegralMenuBtn();
            getSkillBookMenuBtn();
            getQuestMenuBtn();
            getTrepanningMenuBtn();
            /** 7-17-HGC-end */
            getShopGoodsView(this, DeviceEshopUntil.getShopingMenuTreasures());

    }

    private ImageIcon icon;

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        	if (icon == null) {
                icon = CutButtonImage.getImage("inkImg/number/b8/topicon.png", 660, 30);
            }
            g.drawImage(icon.getImage(), 134, -1, 660, 29, this);

    }

    /** 初始化商品 */
    public void getShopGoodsView(ShopOnlineJpanel shopOnlineJpanel, List<Eshop> eshopList) {
    		maxPage = eshopList.size() % 9 == 0 ? eshopList.size() / 9 : eshopList.size() / 9 + 1;
            labpage.setText(nowPage + "/" + maxPage);
            for (int i = 9 * (nowPage - 1); i < 9 * nowPage; i++) {
                int row = i / 3;
                int rank = i % 3;
                if (i >= eshopList.size()) {
                    break;
                }
                goodsMinJpanels[i] = new GoodsMinJpanel(eshopList.get(i));
                goodsMinJpanels[i].setBounds(145 + rank * 220, 60 + row * 120, 210, 110);//修改

                shopOnlineJpanel.add(goodsMinJpanels[i]);
            }

    }

    public void isShopGoods(int shopType) {

        this.shopType = shopType;
        /** "珍品"-6, "技能"-7, "神兽"-8, "仙器"-9, "配饰"-10, "积分"-11  "技能书"-12  "珍品" -13 ""-14*/
        switch (shopType) {
        case 6:
            changeShopGoodsView(DeviceEshopUntil.getShopingMenuTreasures());
            break;
        case 7:
            changeShopGoodsView(DeviceEshopUntil.getShopingMenuSkillJpanel());
            break;
        case 8:
            changeShopGoodsView(DeviceEshopUntil.getShopingMenuGodBeastJpanel());
            break;
        case 9:
            changeShopGoodsView(DeviceEshopUntil.getShopingMenuFairyDeviceJpanel());
            break;
        case 10:
            changeShopGoodsView(DeviceEshopUntil.getShopingMenuAccessoriesJpanel());
            break;
        case 11:
            changeShopGoodsView(DeviceEshopUntil.getShopingMenuPreferentialTreatmentJpanel());
            break;
        case 12:
            changeShopGoodsView(DeviceEshopUntil.getShopingMenuSkillBookJpanel());
            break;
        case 13:
            changeShopGoodsView(DeviceEshopUntil.getShopingMenuQuestJpanel());
            break;
        case 14:
            changeShopGoodsView(DeviceEshopUntil.getShopingMenutrepanningJpanel());
            break;
        default:
            break;
        }
    }

    /** 更换展示的商品 */
    public void changeShopGoodsView(List<Eshop> eshopList) {
        for (int i = 0; i < goodsMinJpanels.length; i++) {
            goodsMinJpanels[i].clearView();
        }
        maxPage = eshopList.size() % 9 == 0 ? eshopList.size() / 9 : eshopList.size() / 9 + 1;
        labpage.setText(nowPage + "/" + maxPage);
        int num = 0;
        for (int i = 9 * (nowPage - 1); i < 9 * nowPage; i++) {
            if (i >= eshopList.size()) {
                break;
            }
            goodsMinJpanels[num].addEshopMessage(eshopList.get(i));
            num++;
        }
    }

    public int getShopType() {
        return shopType;
    }

    public void setShopType(int shopType) {
        this.shopType = shopType;
    }

    public GoodsMinJpanel[] getGoodsMinJpanels() {
        return goodsMinJpanels;
    }

    public void setGoodsMinJpanels(GoodsMinJpanel[] goodsMinJpanels) {
        this.goodsMinJpanels = goodsMinJpanels;
    }

    public TaoBaoBtn getBtnhp() {
        return btnhp;
    }

    public void setBtnhp(TaoBaoBtn btnhp) {
        this.btnhp = btnhp;
    }

    public TaoBaoBtn getBtnep() {
        return btnep;
    }

    public void setBtnep(TaoBaoBtn btnep) {
        this.btnep = btnep;
    }

    public TaoBaoBtn getBtnsyy() {
        return btnsyy;
    }

    public void setBtnsyy(TaoBaoBtn btnsyy) {
        this.btnsyy = btnsyy;
    }

    public TaoBaoBtn getBtnxyy() {
        return btnxyy;
    }

    public void setBtnxyy(TaoBaoBtn btnxyy) {
        this.btnxyy = btnxyy;
    }

    public JLabel getLabpage() {
        return labpage;
    }

    public void setLabpage(JLabel labpage) {
        this.labpage = labpage;
    }

    public int getNowPage() {
        return nowPage;
    }

    public void setNowPage(int nowPage) {
        this.nowPage = nowPage;
    }

    public int getMaxPage() {
        return maxPage;
    }

    public void setMaxPage(int maxPage) {
        this.maxPage = maxPage;
    }





    public TaoBaoBtn getTreasureMenuBtn() {
    		if (treasureMenuBtn == null) {
                treasureMenuBtn = new TaoBaoBtn("inkImg/number/b8/material1.png", 1, "", 10, this);
                treasureMenuBtn.setBounds(150, 0, 64, 28);
                treasureMenuBtn.setFont(new Font("华文楷体", Font.BOLD, 18));
                treasureMenuBtn.setForeground(new Color(114, 85, 36));
                treasureMenuBtn.setOpaque(false);
                this.add(treasureMenuBtn);
            }

        return treasureMenuBtn;
    }

    public void setTreasureMenuBtn(TaoBaoBtn treasureMenuBtn) {
        this.treasureMenuBtn = treasureMenuBtn;
    }

    public TaoBaoBtn getSkillMenuBtn() {
    		if (skillMenuBtn == null) {
                skillMenuBtn = new TaoBaoBtn("inkImg/number/b8/btnxq.png", 1, "", 11, this);
                skillMenuBtn.setBounds(150 + 1 * 66, 0, 64, 28);
                skillMenuBtn.setFont(new Font("华文楷体", Font.BOLD, 18));
                skillMenuBtn.setForeground(new Color(114, 85, 36));
                skillMenuBtn.setOpaque(false);
                this.add(skillMenuBtn);
            }

        return skillMenuBtn;
    }

    public void setSkillMenuBtn(TaoBaoBtn skillMenuBtn) {
        this.skillMenuBtn = skillMenuBtn;
    }

    public TaoBaoBtn getMythicalMenuBtn() {
    		if (mythicalMenuBtn == null) {
                mythicalMenuBtn = new TaoBaoBtn("inkImg/number/b8/btnzhs.png", 1, "", 12, this);
                mythicalMenuBtn.setBounds(150 + 2 * 66, 0, 64, 28);
                mythicalMenuBtn.setFont(new Font("华文楷体", Font.BOLD, 18));
                mythicalMenuBtn.setForeground(new Color(114, 85, 36));
                mythicalMenuBtn.setOpaque(false);
                this.add(mythicalMenuBtn);
            }

        return mythicalMenuBtn;
    }

    public TaoBaoBtn getTrepanningMenuBtn() {
        if (trepanningMenuBtn == null) {
            trepanningMenuBtn = new TaoBaoBtn("inkImg/number/b8/btnhz.png", 1, "", 18, this);
            trepanningMenuBtn.setBounds(150 + 3 * 66, 0, 64, 28);
            this.add(trepanningMenuBtn);
        }

        return trepanningMenuBtn;
    }

     public void setMythicalMenuBtn(TaoBaoBtn mythicalMenuBtn) { this.mythicalMenuBtn = mythicalMenuBtn; }

     public TaoBaoBtn getDeviceMenuBtn() {

         ConfigureBean allConfigure = UserMessUntil.getConfigureBean();
         Map<BigDecimal, Configure> item = allConfigure.getAllConfigure();
         Configure configure = item.get(new BigDecimal(1));
         int szz = 5;//3种族
         if(configure.getLzjskg()!=null) {
             szz = Integer.parseInt(configure.getLzjskg());
         }
         if(szz == 5) {
    		if (deviceMenuBtn == null) {
                deviceMenuBtn = new TaoBaoBtn("inkImg/number/b8/btnlb.png", 1, "", 13, this);
                deviceMenuBtn.setBounds(150 + 4 * 66, 0, 64, 28);
                deviceMenuBtn.setFont(new Font("华文楷体", Font.BOLD, 18));
                deviceMenuBtn.setForeground(new Color(114, 85, 36));
                deviceMenuBtn.setOpaque(false);
                this.add(deviceMenuBtn);
            }
         }
         else if(szz == 4) {
             if (deviceMenuBtn == null) {
                 deviceMenuBtn = new TaoBaoBtn("inkImg/number/b8/btnlb.png", 1, "", 13, this);
                 deviceMenuBtn.setBounds(150 + 4 * 66, 0, 64, 28);
                 deviceMenuBtn.setFont(new Font("华文楷体", Font.BOLD, 18));
                 deviceMenuBtn.setForeground(new Color(114, 85, 36));
                 deviceMenuBtn.setOpaque(false);
                 this.add(deviceMenuBtn);
             }
         }
        return deviceMenuBtn;
     }

       public void setDeviceMenuBtn(TaoBaoBtn deviceMenuBtn) {
          this.deviceMenuBtn = deviceMenuBtn;
     }

     public TaoBaoBtn getBaldricMenuBtn() {

         ConfigureBean allConfigure = UserMessUntil.getConfigureBean();
         Map<BigDecimal, Configure> item = allConfigure.getAllConfigure();
         Configure configure = item.get(new BigDecimal(1));
         int szz = 5;//3种族
         if(configure.getLzjskg()!=null) {
             szz = Integer.parseInt(configure.getLzjskg());
         }

         if(szz == 5) {
    		if (baldricMenuBtn == null) {
               baldricMenuBtn = new TaoBaoBtn("inkImg/number/b8/btnps.png", 1, "", 14, this);
                baldricMenuBtn.setBounds(150 + 5 * 66, 0, 64, 28);
               this.add(baldricMenuBtn);
           }
         }
         else if(szz == 4) {
             if (baldricMenuBtn == null) {
                 baldricMenuBtn = new TaoBaoBtn("inkImg/number/b8/btnps.png", 1, "", 14, this);
                 baldricMenuBtn.setBounds(150 + 5 * 66, 0, 64, 28);
                 this.add(baldricMenuBtn);
             }
         }
        return baldricMenuBtn;
     }

    public void setBaldricMenuBtn(TaoBaoBtn baldricMenuBtn) {
        this.baldricMenuBtn = baldricMenuBtn;
    }

    public TaoBaoBtn getSkillBookMenuBtn() {

        ConfigureBean allConfigure = UserMessUntil.getConfigureBean();
        Map<BigDecimal, Configure> item = allConfigure.getAllConfigure();
        Configure configure = item.get(new BigDecimal(1));
        //翅膀开关
        String cbkg = configure.getCbgnkg();
        int szz = 5;//3种族
        if(configure.getLzjskg()!=null) {
            szz = Integer.parseInt(configure.getLzjskg());
        }

        if(szz == 5) {
//            if(cbkg.equals("开")) {
                if (skillBookMenuBtn == null) {
                    skillBookMenuBtn = new TaoBaoBtn("inkImg/number/b8/btnzp.png", 1, "", 16, this);
                    skillBookMenuBtn.setBounds(150 + 6 * 66, 0, 64, 28);
                    this.add(skillBookMenuBtn);
                }
//            }
        }
        else if(szz == 4) {
//            if(cbkg.equals("开")) {
                if (skillBookMenuBtn == null) {
                    skillBookMenuBtn = new TaoBaoBtn("inkImg/number/b8/btnzp.png", 1, "", 16, this);
                    skillBookMenuBtn.setBounds(150 + 6 * 66, 0, 64, 28);
                    this.add(skillBookMenuBtn);
                }
//            }
        }

        return skillBookMenuBtn;
    }

    public void setSkillBookMenuBtn(TaoBaoBtn skillMenuBtn) {
        this.skillBookMenuBtn = skillMenuBtn;
    }



    public TaoBaoBtn getIntegralMenuBtn() {


        ConfigureBean allConfigure = UserMessUntil.getConfigureBean();
        Map<BigDecimal, Configure> item = allConfigure.getAllConfigure();
        Configure configure = item.get(new BigDecimal(1));
        int szz = 5;//3种族
        if(configure.getLzjskg()!=null) {
            szz = Integer.parseInt(configure.getLzjskg());
        }

        if(szz == 5) {

    		if (integralMenuBtn == null) {
                integralMenuBtn = new TaoBaoBtn("inkImg/number/b8/btnjf.png", 1, "", 15, this);
                integralMenuBtn.setBounds(150 + 7 * 66, 0, 64, 28);
                this.add(integralMenuBtn);
            }

        }
        else if(szz == 4) {

            if (integralMenuBtn == null) {
                integralMenuBtn = new TaoBaoBtn("inkImg/number/b8/btnjf.png", 1, "", 15, this);
                integralMenuBtn.setBounds(150 + 7 * 66, 0, 64, 28);
                this.add(integralMenuBtn);
            }

        }

        else if(szz == 3) {

            if (integralMenuBtn == null) {
                integralMenuBtn = new TaoBaoBtn("inkImg/number/b8/btnjf.png", 1, "", 15, this);
                integralMenuBtn.setBounds(150 + 7 * 66, 0, 64, 28);
                this.add(integralMenuBtn);
            }

        }

        return integralMenuBtn;
    }

    public void setIntegralMenuBtn(TaoBaoBtn integralMenuBtn) {
        this.integralMenuBtn = integralMenuBtn;
    }





    public TaoBaoBtn getQuestMenuBtn() {
    		if (questMenuBtn == null) {
            	questMenuBtn = new TaoBaoBtn("skin/8100226/button/B256.png", 1, "", 17, this);
            	questMenuBtn.setBounds(23, 10, 0, 0);
                this.add(questMenuBtn);
            }

        return questMenuBtn;
    }

    public void setQuestMenuBtn(TaoBaoBtn questMenuBtn) {
        this.questMenuBtn = questMenuBtn;
    }

    public void setTrepanningMenuBtn(TaoBaoBtn trepanningMenuBtn) {
        this.trepanningMenuBtn = trepanningMenuBtn;
    }

}
